package com.yyt.module_main.act;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.yyt.libsrc.bean.BaseCallbackBean;
import com.yyt.libsrc.bean.ShowWithdrawDetailBean;
import com.yyt.libsrc.conf.Consts;
import com.yyt.libsrc.net.JavaParamsBuilder;
import com.yyt.libsrc.net.NetUtil;
import com.yyt.libsrc.net.SuccessCallback;
import com.yyt.libsrc.router.RouteTable;
import com.yyt.module_main.R;
import com.yyt.module_main.databinding.ActivityOrderTraceBinding;
import com.yyt.module_main.vm.OrderTraceVM;

import java.text.SimpleDateFormat;
import java.util.Date;

import top.lixb.libcommon.base.RefreshableActivity;
import top.lixb.libcommon.utils.StringUtils;

@Route(path = RouteTable.main_order_trace)
public class OrderTraceActivity extends RefreshableActivity<ActivityOrderTraceBinding> {

    private OrderTraceVM mVm;

    @Override
    protected void init() {
        mVm = new OrderTraceVM();
        mRefreshContentBinding.setVm(mVm);
        setTitle("订单追踪");
        showToolbarDivider();
        Intent intent = getIntent();
        if (null != intent && null != intent.getExtras()) {
            String reqSn       = intent.getExtras().getString("reqSn");
//            String accountName = intent.getExtras().getString("accountName");
//            String bankName    = intent.getExtras().getString("bankName");
//            String bankNo      = intent.getExtras().getString("bankNo");
//            String amount      = intent.getExtras().getString("amount");
//            String fee         = intent.getExtras().getString("fee");
//            String create_at = intent.getExtras().getString("create_at");

            mVm.reqSn.set(reqSn);
        }
    }

    @Override
    protected int initRefreshLayout() {
        return R.layout.activity_order_trace;
    }

    @Override
    protected void getData(boolean refresh) {
        NetUtil.sellerPost(new JavaParamsBuilder()
                .addCmd(Consts.CMD.showDetails)
                .addP("req_sn",mVm.reqSn.get())
                .build(), new SuccessCallback<ShowWithdrawDetailBean>() {
            @Override
            public void onSuccess(ShowWithdrawDetailBean bean) {
                mVm.accountName.set(bean.data.account_name);
                mVm.amount.set("￥"+StringUtils.doubleFormat(String.valueOf(bean.data.amount-bean.data.fee)));
                mVm.bankName.set(bean.data.bank_name);
                mVm.bankNo.set(bean.data.bank_no);
                mVm.reqSn.set(bean.data.req_sn);
                mVm.fee.set("￥"+StringUtils.doubleFormat(String.valueOf(bean.data.fee)));
                mVm.create_at.set(new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(new Date(bean.data.create_time)));
                mVm.status.set(bean.data.status);
                if (bean.data.status == 1) { //待处理
                    mVm.status_desc.set("订单已提交，请耐心等待");
                    mVm.status_dt.set(new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(new Date(bean.data.create_time)));
                } else if (bean.data.status == 2) { //打款成功
                    mVm.status_desc.set("款项已到账，订单完成");
                    mVm.status_dt.set(new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(new Date(bean.data.create_time)));
                } else if (bean.data.status == 3) { //打款失败
                    mVm.status_desc.set("打款失败");
                    mVm.status_dt.set(new SimpleDateFormat("yy-MM-dd HH:mm:ss").format(new Date(bean.data.create_time)));
                }
            }

            @Override
            public void onComplete() {
                super.onComplete();
                finishGetData();
            }
        });
        // TODO: 2018/8/10 获取状态

    }
}
